import Vue from 'vue';
import Router from 'vue-router';
import Login from '../view/Login.vue'

import { request } from 'http';

Vue.use(Router);

const router = new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    linkActiveClass:'active',
    routes: [
        {
            path: '/',
            redirect: '/login',
            name:'login',
            meta: { title: '慧展数据管理系统'}
        },
        {
            path: '/login',
            name:'login',
            component: Login,
            meta: { title: '慧展数据管理系统' }
        },
        {
            path: '/',
            component: resolve => require(['../components/common/Home.vue'], resolve),
            meta: { title: '自述文件' },
            children:[
                {
                    path: '/dashboard',
                    component: resolve => require(['../view/Dashboard.vue'], resolve),
                    meta: {  title: '首页' }
                },
                // 系统设置
                {
                    path: '/project-manage',
                    component: resolve => require(['../view/system/Project_Manage.vue'], resolve),
                    meta: {
                        title: '项目管理'
                    }
                }, {
                    path: '/project-type',
                    component: resolve => require(['../view/system/Project_Type.vue'], resolve),
                    meta: {
                        title: '项目类型'
                    }
                }, {
                    path: '/user-manage',
                    component: resolve => require(['../view/system/User_Manage.vue'], resolve),
                    meta: {
                        title: '用户管理'
                    }
                }, {
                    path: '/auth-profile',
                    component: resolve => require(['../view/system/Auth_Profile.vue'], resolve),
                    meta: {
                        title: '角色权限配置'
                    }
                }, {
                    path: '/role-manage',
                    component: resolve => require(['../view/system/User_Role_Manage.vue'], resolve),
                    meta: {
                        title: '用户角色管理'
                    }
                }, {
                    path: '/system-log',
                    component: resolve => require(['../view/system/System_log.vue'], resolve),
                    meta: {
                        title: '系统日志'
                    }
                },
                // 票务展-增票管理
                {
                    path: '/import-ticket',
                    component: resolve => require(['../view/ticketing/ticket/Import_ticket.vue'], resolve),
                    meta: { title: '生成实体票' }
                }, {
                    path: '/distribute-ticket',
                    component: resolve => require(['../view/ticketing/ticket/Distribute_Manage.vue'], resolve),
                    meta: { title: '赠票分发' }
                }, {
                    path: '/record-ticket',
                    component: resolve => require(['../view/ticketing/ticket/Record_ticket.vue'], resolve),
                    meta: {
                        title: '赠票记录'
                    }
                }, {
                    path: '/ticket-all',
                    component: resolve => require(['../view/ticketing/ticket/Ticket.vue'], resolve),
                    meta: {
                        title: '查询所有票'
                    }
                },{
                    path: '/mobile-ticket',
                    component: resolve => require(['../view/ticketing/ticket/Mobile_Terminal.vue'], resolve),
                    meta: { title: '生成电子票' }
                }, {
                    path: '/ticket-type-manage',
                    component: resolve => require(['../view/ticketing/ticket/Ticket_Type_Manage.vue'], resolve),
                    meta: {
                        title: '票种管理'
                    }
                },
                // 票务展-证件管理
                {
                    path: '/type-setting',
                    component: resolve => require(['../view/ticketing/certificate/Type_Setting.vue'], resolve),
                    meta: { title: '证件类型' }
                }, {
                    path: '/papers-record',
                    component: resolve => require(['../view/ticketing/certificate/Papers_Recored.vue'], resolve),
                    meta: { title: '证件记录' }
                }, {
                    path: '/head-manage',
                    component: resolve => require(['../view/ticketing/certificate/Head_Manage.vue'], resolve),
                    meta: { title: '头像管理' }
                }, {
                    path: '/distribute-document',
                    component: resolve => require(['../view/ticketing/certificate/Distribute_Manage.vue'], resolve),
                    meta: { title: '证件分发' }
                }, {
                    path: '/record-document',
                    component: resolve => require(['../view/ticketing/certificate/Record_Document.vue'], resolve),
                    meta: { title: '分发记录' }
                },
                // 票务展-售票管理
                {
                    path: '/price-setting',
                    component: resolve => require(['../view/ticketing/sell/Price_Setting.vue'], resolve),
                    meta: { title: '公众号设置' }
                }, {
                    path: '/record-manage',
                    component: resolve => require(['../view/ticketing/sell/Record_Manage.vue'], resolve),
                    meta: { title: '购票记录' }
                },
                // 票务展-数据管理
                {
                    path: '/access-control',
                    component: resolve => require(['../view/ticketing/data/Access_Control.vue'], resolve),
                    meta: { title: '通行规则' }
                }, {
                    path: '/traffic-record',
                    component: resolve => require(['../view/ticketing/data/Traffic_Record.vue'], resolve),
                    meta: { title: '证件通行记录' }
                }, {
                    path: '/ticket-record',
                    component: resolve => require(['../view/ticketing/data/Ticket_Record.vue'], resolve),
                    meta: { title: '票通行记录' }
                }, {
                    path: '/statistics',
                    component: resolve => require(['../view/ticketing/data/Statistics.vue'], resolve),
                    meta: { title: '通行统计' }
                },
                //专业展-展商管理
                {
                    path: '/exhibition',
                    component: resolve => require(['../view/major/businessman/Exhibition_Manage.vue'], resolve),
                    meta: { title: '展商管理' }
                }, {
                    path: '/exhibitors_exhibits',
                    component: resolve => require(['../view/major/businessman/Exhibitors_Exhibits.vue'], resolve),
                    meta: { title: '参展展品' }
                },
                //专业展-组委会
                {
                    path: '/vihicel_manage',
                    component: resolve => require(['../view/major/committee/Vihicel_Manage.vue'], resolve),
                    meta: { title: '车辆管理' }
                }, {
                    path: '/content_publish',
                    component: resolve => require(['../view/major/committee/Content_Publish.vue'], resolve),
                    meta: { title: '内容发布' }
                },
                //专业展 注册UI管理
                {
                    path: '/register_ui_manage',
                    component: resolve => require(['../view/major/RegisterUI_Manage.vue'], resolve),
                    meta: { title: '注册通道' }
                },
                //专业展 观众管理 
                {
                    path: '/audience_manage',
                    component: resolve => require(['../view/major/Peronal.vue'], resolve),
                    meta: { title: '人员管理' }
                },
                //来源管理
                {
                    path: '/source_manage',
                    component: resolve => require(['../view/major/Source.vue'], resolve),
                    meta: { title: '来源管理' }
                },
                //联系人
                {
                    path: '/contact',
                    component: resolve => require(['../view/major/Contact.vue'], resolve),
                    meta: { title: '联系人' }
                },
                //信息模板
                {
                    path: '/Invite',
                    component: resolve => require(['../view/major/Invite.vue'], resolve),
                    meta: { title: '信息模板' }
                },
                //联系人
                {
                    path: '/contact_Invite',
                    component: resolve => require(['../view/major/Contact_Invite.vue'], resolve),
                    meta: { title: '信息记录' }
                },
                {
                    path: '/404',
                    component: resolve => require(['../components/page/404.vue'], resolve),
                    meta: { title: '404' }
                }
            ]
        },
        {
            path: '*',
            redirect: '/404'
        }
    ]
})

router.beforeEach((to, from, next) => {
if (to.matched.some(r => r.meta.requireAuth)) {           //这里的requireAuth为路由中定义的 meta:{requireAuth:true}，意思为：该路由添加该字段，表示进入该路由需要登陆的
     if (to.path == '/login') {
         next();
     } else {
        next({
            path: '/login',
              query: {redirect: to.fullPath}
            })
        }
    }
    else {
        next();
    }
})

export default router;